{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dbc95186-7b27-4f32-9d43-c24d1642c4b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name, score): \n",
    "        self.name = name; \n",
    "        self.score = score; "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "189d2652-bab8-452e-adb2-5fc24b222495",
   "metadata": {},
   "outputs": [],
   "source": [
    "bart = Student('Bart Simpson', 59)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ef66317c-64a6-4638-8d85-f44c8b0ff357",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bart Simpson\n",
      "59\n"
     ]
    }
   ],
   "source": [
    "print(bart.name)\n",
    "print(bart.score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c04fcaa6-b825-484d-89d0-f0424da6a5c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name, score):\n",
    "        self.__name = name\n",
    "        self.__score = score \n",
    "    def print_score(self):\n",
    "        print('%s: %s' % (self.__name, self.__score))\n",
    "\n",
    "    def get_name(self):\n",
    "        return self.__name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7ac25c69-7cec-48cd-b456-cd44116019ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "barts = Student('Bart Simpson', 59)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e562505b-01e3-470e-a340-111b52fd2bcf",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Student' object has no attribute '__name'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mbarts\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__name\u001b[49m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'Student' object has no attribute '__name'"
     ]
    }
   ],
   "source": [
    "barts.__name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5d93aa27-20c0-485b-bb74-6aeb2a7adf41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Bart Simpson'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "barts.get_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a6301242-5402-4fb7-bd92-4e75f62d72bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Animal(object):\n",
    "    def run(self): \n",
    "        print(\"Animal is running...\")\n",
    "class Dog(Animal): \n",
    "    def run(self): \n",
    "        print(\"Dog is running...\")\n",
    "class Cat(Animal): \n",
    "    def run (slef):\n",
    "        print(\"Cat is running...\")\n",
    "\n",
    "def run_twice(animal): \n",
    "    animal.run()\n",
    "    animal.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "88b2d313-0539-41bd-8d5e-45e811cd67b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = Animal()\n",
    "b = Dog() \n",
    "c = Cat() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a574e795-0b5a-47d9-bf55-421f154c87a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a is Animal? True\n",
      "a is Dog? False\n",
      "a is Cat? False\n"
     ]
    }
   ],
   "source": [
    "print(\"a is Animal?\", isinstance(a, Animal))\n",
    "print(\"a is Dog?\", isinstance(a, Dog))\n",
    "print(\"a is Cat?\", isinstance(a, Cat))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e7f24684-cb66-4dff-a5c5-1590d2f0844c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cat is running...\n",
      "Cat is running...\n"
     ]
    }
   ],
   "source": [
    "run_twice(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "44bf5af9-ae48-4fe1-98ed-92388ff27f59",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dog is running...\n",
      "Dog is running...\n"
     ]
    }
   ],
   "source": [
    "run_twice(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7c9bf0a5-1e01-4afd-8226-bf7f0fb444bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Tortoise(Animal):\n",
    "    def run(self):\n",
    "        print('Tortoise is running slowly...')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "72579276-1821-46ae-b1b1-d35e62bea031",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tortoise is running slowly...\n",
      "Tortoise is running slowly...\n"
     ]
    }
   ],
   "source": [
    "run_twice(Tortoise())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc7d41ae-c64c-4607-b67e-317d63bb730d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
